package com.lxm.controller;


import com.lxm.dto.AdminDTO;
import com.lxm.dto.PhonePwdLoginDTO;
import com.lxm.dto.Result;
import com.lxm.service.AdminService;
import com.lxm.service.BlogTypeService;
import com.lxm.service.ItemTypeService;
import com.lxm.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2024-10-02
 */
@RestController
@RequestMapping("/admin")
@Tag(name = "管理员接口")
public class AdminController {
    @Resource
    private ItemTypeService itemTypeService;
    @Resource
    private BlogTypeService blogTypeService;
    @Resource
    private AdminService adminService;
    @Resource
    private LoginService loginService;

    @Operation(summary = "添加管理员")
    @PostMapping("/addAdmin")
    public Result addAdmin(@RequestBody AdminDTO adminDTO) {
        return adminService.addAdmin(adminDTO);
    }

    @Operation(summary = "退出登录")
    @DeleteMapping("/logout")
    public Result logout(HttpServletRequest request) {
        return Result.ok(loginService.logout(request));
    }

    @Operation(summary = "删除管理员")
    @DeleteMapping("/deleteAdmin/{id}")
    public Result deleteAdmin(@PathVariable Long id) {
        return adminService.deleteAdmin(id);
    }

    @Operation(summary = "管理员登录")
    @PostMapping("/AdminLogin")
    public Result adminLogin(@RequestBody PhonePwdLoginDTO login,
                             HttpServletResponse response) {
        return adminService.adminLogin(login, response);
    }

    @Operation(summary = "获取部门管理员列表")
    @GetMapping("/getAdminList/{departmentId}")
    public Result getAdminList(@PathVariable Long departmentId) {
        return adminService.getAdminList(departmentId);
    }

    @Operation(summary = "新增商品类型")
    @PostMapping("/addItemType/{TypeName}")
    public Result addItemType(@PathVariable String TypeName) {
        return itemTypeService.addItemType(TypeName);
    }

    @Operation(summary = "删除商品类型")
    @DeleteMapping("/deleteItemType/{id}")
    public Result deleteItemType(@PathVariable Long id) {
        return itemTypeService.deleteItemType(id);
    }

    @Operation(summary = "修改商品类型")
    @PutMapping("/updateItemType/{id}/{TypeName}")
    public Result updateItemType(@PathVariable Long id, @PathVariable String TypeName) {
        return itemTypeService.updateItemType(id, TypeName);
    }

    @Operation(summary = "新增博客类型")
    @PostMapping("/addBlogType/{TypeName}")
    public Result addBlogType(@PathVariable String TypeName) {
        return blogTypeService.addBlogType(TypeName);
    }

    @Operation(summary = "删除博客类型")
    @DeleteMapping("/deleteBlogType/{id}")
    public Result deleteBlogType(@PathVariable Long id) {
        return blogTypeService.deleteBlogType(id);
    }

    @Operation(summary = "修改博客类型")
    @PutMapping("/updateBlogType/{id}/{TypeName}")
    public Result updateBlogType(@PathVariable Long id, @PathVariable String TypeName) {
        return blogTypeService.updateBlogType(id, TypeName);
    }


}

